/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.xtd.facade.settlement;

import com.xtd.facade.AbstractFacade;
import com.xtd.model.settlement.Form;
import com.xtd.util.FormTypeEnum;
import java.util.List;
import javax.ejb.Stateless;

/**
 *
 * @author Lu Yuanbin
 */
@Stateless
public class FormFacade extends AbstractFacade<Form> {

    public FormFacade() {
        super(Form.class);
    }

    public List findUnSettledForm() {
        return getEntityManager().createQuery("select o from Form as o where o.settled is false").getResultList();
    }

    public List findByNumber(String number, FormTypeEnum formType) {
        if (number == null) {
            number = "";
        }
        if (formType == null) {
            return getEntityManager().createQuery("select o from Form as o where o.number like :number ").setParameter("number", "%" + number + "%").getResultList();
        }

        return getEntityManager().createQuery("select o from Form as o where o.number like :number and o.type = :type").setParameter("number", "%" + number + "%").setParameter("type", formType).getResultList();
    }

    public List findByType(FormTypeEnum formType) {

        return getEntityManager().createQuery("select o from Form as o where  o.type = :type").setParameter("type", formType).getResultList();
    }
}
